/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.star.modules.sys.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.star.modules.sys.entity.ShQuestion;
import com.star.modules.sys.service.ShQuestionService;

/**
 * 答疑Controller
 * @author L
 * @version 2018-09-04
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/shQuestion")
public class ShQuestionController extends BaseController {

	@Autowired
	private ShQuestionService shQuestionService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ShQuestion get(String id, boolean isNewRecord) {
		return shQuestionService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("sys:shQuestion:view")
	@RequestMapping(value = {"list", ""})
	public String list(ShQuestion shQuestion, Model model) {
		model.addAttribute("shQuestion", shQuestion);
		return "modules/sys/shQuestionList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("sys:shQuestion:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ShQuestion> listData(ShQuestion shQuestion, HttpServletRequest request, HttpServletResponse response) {
		Page<ShQuestion> page = shQuestionService.findPage(new Page<ShQuestion>(request, response), shQuestion); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("sys:shQuestion:view")
	@RequestMapping(value = "form")
	public String form(ShQuestion shQuestion, Model model) {
		model.addAttribute("shQuestion", shQuestion);
		return "modules/sys/shQuestionForm";
	}

	/**
	 * 保存答疑
	 */
	@RequiresPermissions("sys:shQuestion:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ShQuestion shQuestion) {
		shQuestionService.save(shQuestion);
		return renderResult(Global.TRUE, "保存答疑成功！");
	}
	
	/**
	 * 停用答疑
	 */
	@RequiresPermissions("sys:shQuestion:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(ShQuestion shQuestion) {
		shQuestion.setStatus(ShQuestion.STATUS_DISABLE);
		shQuestionService.updateStatus(shQuestion);
		return renderResult(Global.TRUE, "停用答疑成功");
	}
	
	/**
	 * 启用答疑
	 */
	@RequiresPermissions("sys:shQuestion:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(ShQuestion shQuestion) {
		shQuestion.setStatus(ShQuestion.STATUS_NORMAL);
		shQuestionService.updateStatus(shQuestion);
		return renderResult(Global.TRUE, "启用答疑成功");
	}
	
	/**
	 * 删除答疑
	 */
	@RequiresPermissions("sys:shQuestion:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ShQuestion shQuestion) {
		shQuestionService.delete(shQuestion);
		return renderResult(Global.TRUE, "删除答疑成功！");
	}
	
}